﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'tablePlug', 'treeTable',"layer"], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer,
            treeTable = layui.treeTable, treeTable1 = layui.treeTable,
            common = layui.common;
        //加载数据
        var loading = layer.load(0, { shade: false });
        var queryJson = '';
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        toolbarDemo1.innerHTML = common.authorizeButtonNew(toolbarDemo1.innerHTML);

        var rendertree1 = common.rendertreetable({
            elem: '#currentTableId1',
            sqlkey: 'F_Id',//数据库主键
            //懒加载设置
            tree: {
                iconIndex: 1,           // 折叠图标显示在第几列
                idName: 'F_Id',  // id字段名称
                arrowType: 'arrow2',
                getIcon: 'ew-tree-icon-style2',
                haveChildName: 'haveChild'  // 自定义标识是否还有子节点的字段名称
            },
            reqData: function (data, callback) {
                var pid = data ? data.F_Code : '0';
                common.ajax({
                    url: "/BasicData/Hierarchies/GetListJson",
                    dataType: "json",
                    //懒加载的查询参数放这里
                    data: { keyValue: pid, keyword: $('#txt_keyword').val() },
                    async: false,
                    success: function (data) {
                        callback(data.data);
                    }
                });
            },
            cols: [[
                { field: 'F_Id', title: 'ID', sort: true, fixed: "left", hide: true, hideAlways: true },
                { field: 'F_Name', title: '名称', width: 350, event: 'setSign', style: 'cursor: pointer;' },
                { field: 'F_Code', title: '代码', width: 120 },
                { field: 'F_Level', title: '级别', width: 60 }
            ]]
        });

        var rendertree = common.rendertreetable({
            elem: '#currentTableId',
            sqlkey: 'F_Id',//数据库主键
            //懒加载设置
            tree: {
                iconIndex: 1,           // 折叠图标显示在第几列
                idName: 'F_Id',  // id字段名称
                arrowType: 'arrow2',
                getIcon: 'ew-tree-icon-style2',
                haveChildName: 'haveChild'  // 自定义标识是否还有子节点的字段名称
            },
            reqData: function (data, callback) {
                var pid = data ? data.F_Code : '0';
                common.ajax({
                    url: "/BasicData/Equipments/GetListJson",
                    dataType: "json",
                    //懒加载的查询参数放这里
                    data: { keyValue: pid, keyword: $('#txt_keyword').val() },
                    async: false,
                    success: function (data) {
                        callback(data.data);
                    }
                });
            },
            cols: [[
                { field: 'F_Id', title: 'ID', sort: true, fixed: "left", hide: true, hideAlways: true },
                { field: 'F_Name', title: '名称', width: 350 },
                { field: 'F_Code', title: '代码', width: 120 },
                { field: 'F_Level', title: '级别', width: 60 }
            ]]
        });

        // 监听搜索操作
        //form.on('submit(data-search-btn)', function (data) {
        //    common.reloadtreetable(rendertree, {});
        //    duty = null;
        //    return false;
        //});
        var duty;
        treeTable.on('row(currentTableId)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            duty = obj;
        })

        var duty1;
        treeTable1.on('row(currentTableId1)', function (obj) {
            //alert(obj.data.F_Code);
            common.reloadtreetable(rendertree, {});
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            duty1 = obj;
        })
        /**
         * toolbar监听事件
         */

        treeTable.on('toolbar(currentTableId)', function (obj) {
            if (obj.event === 'add') {  // 监听操作
                keyValue = !!duty ? duty.data.F_Id : null;
                common.modalOpen({
                    title: "添加区域",
                    url: "/BasicData/Equipments/Form?event=add&keyValue=" + keyValue,
                    width: "450px",
                    height: "450px",
                });
            }
            else if (obj.event === 'delete') {
                if (duty == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/BasicData/Equipments/DeleteForm",
                    param: { keyValue: duty.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (duty == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑区域",
                    url: "/BasicData/Equipments/Form?event=edit&keyValue=" + duty.data.F_Id,
                    width: "450px",
                    height: "450px",
                });
            }
            return false;
        });
        treeTable1.on('toolbar(currentTableId1)', function (obj) {
            if (obj.event === 'add') {  // 监听操作
                keyValue = !!duty1 ? duty1.data.F_Id : null;
                common.modalOpen({
                    title: "添加区域",
                    url: "/BasicData/Hierarchies/Form?event=add&keyValue=" + keyValue,
                    width: "450px",
                    height: "450px",
                });
            }
            else if (obj.event === 'delete') {
                if (duty1 == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/BasicData/Hierarchies/DeleteForm",
                    param: { keyValue: duty1.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (duty1 == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑区域",
                    url: "/BasicData/Hierarchies/Form?event=edit&keyValue=" + duty1.data.F_Id,
                    width: "450px",
                    height: "450px",
                });
            }
            return false;
        });
    });
</script>
<div class="layui-fluid" style="padding:0 0px">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-card" style="text-align:left;padding: 5px;" id="toolbarDiv">
                

                <script type="text/html" id="toolbarDemo1">
                    <div class="layui-btn-container" id="toolbar1">
                        <button id="NF-add1" authorize="yes" class="layui-btn  data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                        <button id="NF-edit1" authorize="yes" class="layui-btn  layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                        <button id="NF-delete1" authorize="yes" class="layui-btn  layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                        <button id="NF-details1" authorize="yes" class="layui-btn  layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                    </div>
                </script>
                <table class="layui-hide" id="currentTableId1" lay-filter="currentTableFilter"></table>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-card" style="padding: 5px;">

                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container" id="toolbar">
                        <button id="NF-add" authorize="yes" class="layui-btn  data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                        <button id="NF-edit" authorize="yes" class="layui-btn  layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                        <button id="NF-delete" authorize="yes" class="layui-btn  layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                        <button id="NF-details" authorize="yes" class="layui-btn  layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                    </div>
                </script>

                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
        </div>
    </div>
</div>
